package org.assertj.ohos.api.view;

import ohos.agp.components.ComponentContainer;

import static org.assertj.ohos.internal.BitmaskUtils.buildNamedValueString;
import static org.assertj.core.api.Assertions.assertThat;

public abstract class AbstractViewGroupAssert<S extends AbstractViewGroupAssert<S, A>, A extends ComponentContainer>
    extends AbstractViewAssert<S, A> {
  protected AbstractViewGroupAssert(A actual, Class<S> selfType) {
    super(actual, selfType);
  }
/* // TODO: wang, not found in ohos
  public S isAddingStatesFromChildren() {
    isNotNull();
    assertThat(actual.addStatesFromChildren()) //
        .overridingErrorMessage("Expected adding states from children but was not") //
        .isTrue();
    return myself;
  }

  public S isNotAddingStatesFromChildren() {
    isNotNull();
    assertThat(actual.addStatesFromChildren()) //
        .overridingErrorMessage("Expected not adding states from children but was") //
        .isFalse();
    return myself;
  }*/

  public S hasChildCount(int count) {
    isNotNull();
    int actualCount = actual.getChildCount();
    assertThat(actualCount) //
        .overridingErrorMessage("Expected child count <%s> but was <%s>", count, actualCount) //
        .isEqualTo(count);
    return myself;
  }

  public S hasDescendantFocusability(int focusability) {
    isNotNull();
    int actualFocusability = actual.getFocusOrder();
    //noinspection ResourceType
    assertThat(actualFocusability) //
        .overridingErrorMessage("Expected descendant focusability <%s> but was <%s>",
            descendantFocusabilityToString(focusability),
            descendantFocusabilityToString(actualFocusability)) //
        .isEqualTo(focusability);
    return myself;
  }
/* // TODO: wang, not found in ohos
  public S hasFocusedChild(View view) {
    isNotNull();
    View actualView = actual.getFocusedChild();
    assertThat(actualView) //
        .overridingErrorMessage("Expected focused child <%s> but was <%s>", view, actualView) //
        .isSameAs(view);
    return myself;
  }

  public S hasLayoutMode(@ViewGroupLayoutMode int layoutMode) {
    isNotNull();
    int actualLayoutMode = actual.getLayoutMode();
    //noinspection ResourceType
    assertThat(actualLayoutMode) //
        .overridingErrorMessage("Expected layout mode <%s> but was <%s>.",
            layoutModeToString(layoutMode), layoutModeToString(actualLayoutMode)) //
        .isEqualTo(layoutMode);
    return myself;
  }

  public S hasPersistentDrawingCache(@ViewGroupPersistentDrawingCache int cache) {
    isNotNull();
    int actualCache = actual.getPersistentDrawingCache();
    //noinspection ResourceType
    assertThat(actualCache) //
        .overridingErrorMessage("Expected persistent drawing cache <%s> but was <%s>",
            persistentDrawingCacheToString(cache), persistentDrawingCacheToString(actualCache)) //
        .isEqualTo(cache);
    return myself;
  }

  public S isAlwaysDrawnWithCache() {
    isNotNull();
    assertThat(actual.isAlwaysDrawnWithCacheEnabled()) //
        .overridingErrorMessage("Expected to always draw with cache but was not") //
        .isTrue();
    return myself;
  }

  public S isNotAlwaysDrawnWithCache() {
    isNotNull();
    assertThat(actual.isAlwaysDrawnWithCacheEnabled()) //
        .overridingErrorMessage("Expected to not always draw with cache but was") //
        .isFalse();
    return myself;
  }

  public S isClippingChildren() {
    isNotNull();
    assertThat(actual.getClipChildren()) //
        .overridingErrorMessage("Expected to be clipping children but was not.") //
        .isTrue();
    return myself;
  }

  public S isNotClippingChildren() {
    isNotNull();
    assertThat(actual.getClipChildren()) //
        .overridingErrorMessage("Expected to not be clipping children but was.") //
        .isFalse();
    return myself;
  }

  public S hasAnimationCacheEnabled() {
    isNotNull();
    assertThat(actual.isAnimationCacheEnabled()) //
        .overridingErrorMessage("Expected animation cache enabled but was disabled") //
        .isTrue();
    return myself;
  }

  public S hasAnimationCacheDisabled() {
    isNotNull();
    assertThat(actual.isAnimationCacheEnabled()) //
        .overridingErrorMessage("Expected animation cache disabled but was enabled") //
        .isFalse();
    return myself;
  }

  public S hasMotionEventSplittingEnabled() {
    isNotNull();
    assertThat(actual.isMotionEventSplittingEnabled()) //
        .overridingErrorMessage("Expected motion event splitting enabled but was disabled") //
        .isTrue();
    return myself;
  }

  public S hasMotionEventSplittingDisabled() {
    isNotNull();
    assertThat(actual.isMotionEventSplittingEnabled()) //
        .overridingErrorMessage("Expected motion event splitting disabled but was enabled") //
        .isFalse();
    return myself;
  }*/

  public static String descendantFocusabilityToString(int focusability) {
    return buildNamedValueString(focusability)
        .value(ComponentContainer.FOCUS_CHILDREN_FIRST, "childrenFirst")
        .value(ComponentContainer.FOCUS_PARENT_FIRST, "parentFirst")
        .value(ComponentContainer.FOCUS_CHILDREN_HIDE, "childrenHide")
        .get();
  }
/* // TODO: wang, not found in ohos
  public static String persistentDrawingCacheToString(@ViewGroupPersistentDrawingCache int cache) {
    return buildNamedValueString(cache)
        .value(PERSISTENT_ALL_CACHES, "all")
        .value(PERSISTENT_ANIMATION_CACHE, "animation")
        .value(PERSISTENT_NO_CACHE, "none")
        .value(PERSISTENT_SCROLLING_CACHE, "scrolling")
        .get();
  }

  public static String layoutModeToString(@ViewGroupLayoutMode int layoutMode) {
    return buildNamedValueString(layoutMode)
        .value(LAYOUT_MODE_CLIP_BOUNDS, "clip_bounds")
        .value(LAYOUT_MODE_OPTICAL_BOUNDS, "optical_bounds")
        .get();
  }*/
}
